//
//  RBRegisterLoginViewController.m
//  Budejie
//
//  Created by 华杨科技 on 2017/9/24.
//  Copyright © 2017年 饶波. All rights reserved.
//

#import "RBRegisterLoginViewController.h"

@interface RBRegisterLoginViewController ()
@property (weak, nonatomic) IBOutlet UIButton *loginButton;


/**
 登录模块，左边间距
 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leftMargin;

@end

@implementation RBRegisterLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    /*** 设置圆角的三种方式 
    // 方式一：
//    self.loginButton.layer.masksToBounds = YES;
//    self.loginButton.layer.cornerRadius = 5;
    
    // 方式二：KVC 
//    [self.loginButton setValue:@5 forKeyPath:@"layer.cornerRadius"];
//    [self.loginButton setValue:@YES forKeyPath:@"layer.masksToBounds"];
    
    // 方式三： 通过xib 设置圆角 第三个，
//    User Defined Runtime Attributes
     
     ***/
    
}

// 设置状态栏为颜色
- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}


// 隐藏状态条
//- (BOOL)prefersStatusBarHidden {
//    return YES;
//}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
//    [self dismissViewControllerAnimated:YES completion:nil];
    [self.view endEditing:YES];
}

#pragma mark - button点击事件


/**
 关闭
 */
- (IBAction)dismissAction {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}



/**
 显示登录或设置界面

 @param sender sender
 */
- (IBAction)showLoginOrRegister:(UIButton *)sender {

    // 退出键盘
    [self.view endEditing:YES];
    
    // 设置约束和按钮文字
    if (self.leftMargin.constant) { // 目前显示的是注册界面，点击按钮切换到注册界面
        self.leftMargin.constant = 0; // 清零
        [sender setTitle:@"注册帐号" forState:(UIControlStateNormal)];
    }else { // 目前显示的登录界面，点击按钮后切换为注册界面        
        self.leftMargin.constant = -self.view.rb_width;
        [sender setTitle:@"已有账号" forState:UIControlStateNormal];
    }
    
    
    [UIView animateWithDuration:0.25 animations:^{
        // UI的刷新代码:修改UI界面的代码
        
        // 强制刷新 : 让最新设置的约束值马上作用到UI控件上
        [self.view layoutIfNeeded];
    }];
    
}



@end
